package controller

import (
	"encoding/json"
	"net/http"

	"gitee.com/wangshh_123/cross-pay-go/src/utils/common"

	"github.com/gin-gonic/gin"
)

// HealthCheck 健康检查接口
func HealthCheck(c *gin.Context) {
	common.Success(c, gin.H{
		"status":  "ok",
		"message": "health_check_ok",
	})
}

// HelloWorld Hello World接口
func HelloWorld(c *gin.Context) {
	common.Success(c, gin.H{
		"message": "welcome_message",
	})
}

// Response 通用响应结构
type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

// BaseController 基础控制器
type BaseController struct{}

// Success 返回成功响应
func (c *BaseController) Success(w http.ResponseWriter, data interface{}) {
	c.JSON(w, http.StatusOK, Response{
		Code:    0,
		Message: "success",
		Data:    data,
	})
}

// Error 返回错误响应
func (c *BaseController) Error(w http.ResponseWriter, code int, message string) {
	c.JSON(w, code, Response{
		Code:    code,
		Message: message,
	})
}

// JSON 返回JSON响应
func (c *BaseController) JSON(w http.ResponseWriter, code int, data interface{}) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	json.NewEncoder(w).Encode(data)
}
